<?php

/**
 * [PHPFOX_HEADER]
 */
defined('PHPFOX') or exit('NO DICE!');

/**
 * 
 * 
 * @copyright		[PHPFOX_COPYRIGHT]
 * @author  		Raymond Benc
 * @package 		Phpfox_Component
 * @version 		$Id: index.class.php 300 2009-03-20 13:01:54Z Raymond_Benc $
 */
class Sms_Component_Controller_Index extends Phpfox_Component {

    /**
     * Class process method wnich is used to execute this component.
     */
    public function process() {
        Phpfox::isUser(TRUE);
        
        if (($aVals = $this->request()->getArray('val'))){
            //include file service
            include(PHPFOX_DIR . 'hoiio/HoiioService.php');
            
            $hoiioService = new HoiioService(Phpfox::getParam('sms.hoiio_app_id'), Phpfox::getParam('sms.hoiio_access_token'));
            
            if(Phpfox_Error::isPassed()) {
                try {
                    //send SMS
                    $hoiioService->sms($aVals['recipient'], $aVals['message'], substr(Phpfox::getParam('sms.sender_name') , 0, 11));
                    
                    $this->url()->send('current', NULL, 'SMS send successfully');
                } catch (HoiioException $e) {
                    Phpfox_Error::set($e->getMessage());
                }
            }
        }
//        try {
//            var_dump($hoiioService->sms('841649663756', 'HelloWorld'));
//        }  catch (HoiioException $e) {
//            echo $e->getMessage();
//        }
        
        

        $this->template()->setTitle('SMS')
                ->setBreadcrumb('SMS');
    }

    /**
     * Garbage collector. Is executed after this class has completed
     * its job and the template has also been displayed.
     */
    public function clean() {
        (($sPlugin = Phpfox_Plugin::get('sms.component_controller_index_clean')) ? eval($sPlugin) : false);
    }

}

?>